package com.h2.gwt.util.chain;

import java.util.List;
import java.util.ListIterator;

public class FilterChain<T> implements IFilterChain<T> {
   
   private List<IFilterChain<T>> _filters;
   
   private ListIterator<IFilterChain<T>> _nextFilter;
   
   ////
   
   public void startFilter(T obj) {
      setNextFilter(getFilters().listIterator());
      doFilter(obj, this);
   }
   
   public void doFilter(T obj, IFilterChain<T> filterChain) {
      if(getNextFilter().hasNext()) {
         getNextFilter().next().doFilter(obj, filterChain);
      }
   }

   /**
    * @return the filters
    */
   public List<IFilterChain<T>> getFilters() {
      return _filters;
   }

   /**
    * @param filters the filters to set
    */
   public void setFilters(List<IFilterChain<T>> filters) {
      _filters = filters;
   }

   /**
    * @return the nextFilter
    */
   public ListIterator<IFilterChain<T>> getNextFilter() {
      return _nextFilter;
   }

   /**
    * @param nextFilter the nextFilter to set
    */
   public void setNextFilter(ListIterator<IFilterChain<T>> nextFilter) {
      _nextFilter = nextFilter;
   }

}
